package com.manrai.springpractice.domain;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.springmodules.validation.bean.conf.loader.annotation.handler.Email;
import org.springmodules.validation.bean.conf.loader.annotation.handler.Expression;
import org.springmodules.validation.bean.conf.loader.annotation.handler.MaxLength;
import org.springmodules.validation.bean.conf.loader.annotation.handler.NotBlank;

import com.sun.istack.internal.NotNull;

/**
 * User domain model + form backing bean(not ideal but convenient for now!)
 * 
 * @author mmanrai
 * 
 */
public class User {

	@NotBlank
	@MaxLength(40)
	private String firstName;

	@NotBlank
	@MaxLength(40)
	private String lastName;
	
	@NotBlank
	@MaxLength(20)
	private String username;
	
	@NotBlank
	@MaxLength(80)
	@Email
	private String email;
	
	@NotBlank
	@MaxLength(20)
	@Expression(value = "password equals passwordConfirmation",
			errorCode = "password.not.match")
	private String password;
	
	private String passwordConfirmation; // form backing bean field
	
	private boolean marketingOk = true;
	
	@Expression(value = "acceptTerms equals true",
			errorCode = "terms.not.accepted")
	private boolean acceptTerms = false;
	
	private boolean enabled = true;

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPasswordConfirmation() {
		return passwordConfirmation;
	}

	public void setPasswordConfirmation(String passwordConfirmation) {
		this.passwordConfirmation = passwordConfirmation;
	}

	public boolean isMarketingOk() {
		return marketingOk;
	}

	public void setMarketingOk(boolean marketingOk) {
		this.marketingOk = marketingOk;
	}

	public boolean isAcceptTerms() {
		return acceptTerms;
	}

	public void setAcceptTerms(boolean acceptTerms) {
		this.acceptTerms = acceptTerms;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
		.append("firstName", this.firstName)
		.append("lastName", this.lastName)
		.append("email", this.email)
		.append("username", this.username)
		.append("acceptTerms", this.acceptTerms)
		.append("marketingOk", this.marketingOk)
		.toString();
	}
}
